package com.dqx.haoqiu.mvp.common.base;

import com.dqx.haoqiu.mvp.BuildConfig;
import com.dqx.haoqiu.mvp.R;
import com.dqx.haoqiu.mvp.common.dagger.AppComponent;
import com.dqx.haoqiu.mvp.common.dagger.AppModule;
import com.dqx.haoqiu.mvp.common.dagger.DaggerAppComponent;
import com.dqx.haoqiu.mvp.common.webview.vassonic.SonicRuntimeImpl;
import com.dqx.haoqiu.mvp.common.config.AppConfig;
import com.squareup.leakcanary.LeakCanary;
import com.tencent.sonic.sdk.SonicConfig;
import com.tencent.sonic.sdk.SonicEngine;
import com.xmjs.baselibrary.base.application.LibBaseApplication;
import com.xmjs.baselibrary.utils.BuglyUtils;
import com.xmjs.baselibrary.utils.Density;
import com.xmjs.baselibrary.utils.Logger;

public class BaseApplication extends LibBaseApplication {

    private static AppComponent sAppComponent;

    @Override
    public void onCreate() {
        super.onCreate();

        //Dagger依赖注入
        sAppComponent = DaggerAppComponent.builder()
                .appModule(new AppModule(this))
                .build();
        sAppComponent.inject(this);

        //强制设置屏幕密度以到达适配目的
        Density.setDensity(this, 375);

        //APP配置（需要先配置这个）
        AppConfig.initConfig(this);

        //是否开启日志：true-打开、false-关闭
        Logger.setDevelopMode(BuildConfig.DEBUG);

        //初始化腾讯bugly
        BuglyUtils.initDefault(this, AppConfig.BUGLY_ID, R.mipmap.ic_launcher);

        //初始化腾讯VasSonic
        if (!SonicEngine.isGetInstanceAllowed())
            SonicEngine.createInstance(new SonicRuntimeImpl(this), new SonicConfig.Builder().build());

        //安装LeakCanary
        if (BuildConfig.DEBUG && !LeakCanary.isInAnalyzerProcess(this))
            LeakCanary.install(this);
    }

    public static AppComponent getAppComponent() {
        return sAppComponent;
    }

}
